package cn.jiyun.controller;

import cn.jiyun.bean.User;
import cn.jiyun.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/4/20.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService service;
    @RequestMapping("goadd")
    public String adda(){
        return "add";
    }
    @RequestMapping("add")
    public String add(User user){
        service.add(user);
        return "redirect:list.do";
    }
    //查询
    @RequestMapping("list")
    public String list(User user, Model model){
        List<User> all = service.findAll();
        model.addAttribute("list",all);
        return "list";
    }
    //删除
    @RequestMapping("del")
    public String del(Integer uid){
        service.del(uid);
        return "redirect:list.do";
    }
}
